package com.toocms.jinjuhang.ui.index

import android.content.Context
import android.os.Bundle
import android.view.View
import android.widget.FrameLayout
import android.widget.TextView
import android.widget.ViewFlipper
import androidx.databinding.ObservableArrayList
import com.blankj.utilcode.util.ConvertUtils
import com.toocms.jinjuhang.config.Constants
import com.toocms.jinjuhang.data.index.NoticeData
import com.toocms.jinjuhang.ui.index.article_details.ArticleDetailsFgt
import com.toocms.tab.base.BaseViewModel
import com.toocms.tab.base.MultiItemViewModel

class IndexMessageItemModel(viewModel: BaseViewModel<*>, items: List<NoticeData>) :
    MultiItemViewModel<BaseViewModel<*>>(viewModel) {

//    val itemClickBindingCommand = BindingCommand<BindingAction>(BindingAction {
//        item.get()?.apply {
//            val bundle=Bundle()
//            bundle.putString(Constants.BundleKey.KEY_NEWS_ID,news_id)
//            viewModel.startFragment(ArticleDetailsFgt::class.java,bundle)
//        }
//    })

    val items by lazy {
        val result = ObservableArrayList<NoticeData>()
        result.addAll(items)
        result
    }

    val itemFactory: (context: Context, parent: ViewFlipper, data: NoticeData) -> View =
        { context, parent, data ->
            TextView(context).apply {
                layoutParams = FrameLayout.LayoutParams(
                    FrameLayout.LayoutParams.MATCH_PARENT,
                    FrameLayout.LayoutParams.WRAP_CONTENT
                )
                setPadding(
                    0,
                    ConvertUtils.dp2px(10f),
                    0,
                    ConvertUtils.dp2px(10f)
                )
                text = data.title
                setTextColor(0xFF333333.toInt())
                textSize=12f
                setOnClickListener {
                    val bundle = Bundle()
                    bundle.putString(Constants.BundleKey.KEY_NEWS_ID, data.news_id)
                    viewModel.startFragment(ArticleDetailsFgt::class.java, bundle)
                }
            }
        }

    init {
        itemType = Constants.RecyclerViewItemType.ITEM_TYPE_THREE
    }
}